package com.slkj.shilixiaoyuanapp.ui.common.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.slkj.shilixiaoyuanapp.R;
import com.slkj.shilixiaoyuanapp.ui.common.LookPicActivity__JumpCenter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created  on 2018/7/3 0003
 *
 * @author 唐开阔
 * @describe 选择图片适配器
 */
public class ChosePicAndNetAdapter extends BaseQuickAdapter<ChosePicAndNetAdapter.Data, BaseViewHolder> {
    private Context context;
    private ArrayList<Data> picPaths = new ArrayList<>();
    //是否可以删除
    private boolean isFromNet = false;



    public ChosePicAndNetAdapter(@Nullable ArrayList<Data> picPaths, Context context, boolean isFromNet) {
        super(R.layout.item_chose_pic, picPaths);
        this.context = context;
        this.isFromNet = isFromNet;
        this.picPaths = picPaths;
    }

    public ChosePicAndNetAdapter(@Nullable List<Data> picPaths, Context context, boolean isFromNet) {
        super(R.layout.item_chose_pic, picPaths);
        this.context = context;
        this.isFromNet = isFromNet;
        this.picPaths.addAll(picPaths);
    }

    @Override
    protected void convert(BaseViewHolder helper, Data item) {
        Glide.with(context).load(item.getPath())
                .fallback(R.drawable.ic_man)
                .error(R.drawable.ic_man)
                .into((ImageView) helper.getView(R.id.imageView));
        helper.setOnClickListener(R.id.img_delete, v -> {
            picPaths.remove(helper.getAdapterPosition());
            notifyItemRemoved(helper.getAdapterPosition());
        }).setVisible(R.id.img_delete, !isFromNet)
                .itemView.setOnClickListener(v ->
                    LookPicActivity__JumpCenter.builder(context)
//                        .setImgUrls(item.getPath())
                        .setStartPos(helper.getAdapterPosition())
                        .create().go());
    }
    static  class Data{
        private String path;
        private boolean isNet;

        public Data(String path, boolean isNet) {
            this.path = path;
            this.isNet = isNet;
        }

        public String getPath() {
            return path;
        }

        public void setPath(String path) {
            this.path = path;
        }

        public boolean isNet() {
            return isNet;
        }

        public void setNet(boolean net) {
            isNet = net;
        }
    }
}
